package com.yugu.util;

import java.util.Base64;

public class Base64Utils {
    /**
     * //加密
     * @param str
     * @return
     */
    public static String getBase64Encode(String str){
        if(StringUtils.isNotEmpty(str)){
            str=Base64.getEncoder().encodeToString(str.getBytes());
            return str;
        }else{
            return "";
        }
    }

    /**
     * 解密
     * @param str
     * @return
     */
    public static String getBase64Decode(String str){
        if(StringUtils.isNotEmpty(str)){
            byte[] bytes = Base64.getDecoder().decode(str);
            String res = new String(bytes);
            return res;
        }else{
            return str;
        }
    }

    public static void main(String[] args) {
        String base64Decode = getBase64Encode("/123/1");
        System.out.println(base64Decode);
        String base64Decode1 = getBase64Decode(base64Decode);
        System.out.println(base64Decode1);
    }
}
